package top.kaoshanji.r1ch04a.config;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import top.kaoshanji.r1ch04a.binarytea.BinaryTeaApplication;
import top.kaoshanji.r1ch04a.binarytea.BinaryTeaProperties;

/**
 * 代码清单test-r1ch04a-82页a：自动配置类有效
 * @author kaoshanji
 * ^_^
 * create time 2025/5/28 17:56
 */
@SpringBootTest(classes = BinaryTeaApplication.class, properties = {
        "binarytea.ready=true",
        "binarytea.open-hours=8:30-22:00"
})
public class ShopConfigurationEnableTest {

    @Autowired
    private ApplicationContext applicationContext;

    @Test
    public void testPropertiesBeanAvailable() {
        Assertions.assertNotNull(applicationContext.getBean(BinaryTeaProperties.class));
        Assertions.assertTrue(applicationContext.containsBean("binarytea-top.kaoshanji.r1ch04a.binarytea.BinaryTeaProperties"));
    }

    @Test
    public void testPropertyValues() {
        BinaryTeaProperties properties = applicationContext.getBean(BinaryTeaProperties.class);

        Assertions.assertTrue(properties.isReady());
        Assertions.assertEquals("8:30-22:00", properties.getOpenHours());
    }

}
